package url;

import java.sql.*;
public class DBUtil {
	public static Connection con;
	public static Statement st;
	public static PreparedStatement ps;
	public static ResultSet rs = null;
	static final String url = "jdbc:mysql://localhost:3306/test";
	static String name = "root";
	static String pwd = "123456";

	public static void initst() {
		try {
			con = DriverManager.getConnection(url, name, pwd);
		} catch (SQLException e) {
			e.printStackTrace();
		}
    }

	public static void select(String sql) {
		try {
			ps = con.prepareStatement(sql);
			rs = ps.executeQuery();

		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	public static void uodate(String sql) {
		try {
			ps = con.prepareStatement(sql);
			ps.executeUpdate();
		} catch (SQLException e) {
			e.printStackTrace();
		}
    }

	///231213213
	public static void closeDB() {
		try {
			if (rs != null) {
				rs.close();
			}
			if (ps != null) {
				ps.close();
			}
			if (st != null) {
				st.close();
			}
			if (con != null) {
				con.close();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

	}
}